package com.grp6.game.ui.platform.text.ansi;

import java.util.ArrayList;

import com.grp6.game.ui.platform.IActionListener;
import com.grp6.game.ui.platform.ICell;

public class AnsiCharacterCell implements ICell {
	private int x;
	private int y;
	private boolean highlight = false;
	private ColorPrinter out;
	private UICellMapper uimap;
	private Color fgColor;
	private Color bgColor;
	private char _char = ' ';
	private ArrayList<IActionListener> listeners = new ArrayList<IActionListener>();
	
	public AnsiCharacterCell(int x, int y,ColorPrinter out,UICellMapper uimap) {
		this.x = x+1;
		this.y = y+1;
		this.out = out;
		this.uimap = uimap;
		print();
	}

	@Override
	public void setTile(String tile) {
		this.bgColor = uimap.toBGColor(tile);
		print();
	}
	
	@Override
	public void setSymbol(String symbol) {
		this.fgColor = uimap.toFGColor(symbol);
		this._char = uimap.toChar(symbol);
		this.setHighlight(uimap.toFGLight(symbol));
		print();
	}

	@Override
	public void setHighlight(boolean on) {
		this.highlight = on;
		print();
	}

	private void print() {
		out.moveTo(x, y)
			.bg(bgColor)
			.fg(fgColor,highlight)
			.print(_char);
	}


	@Override
	public void addActionListerner(IActionListener listener) {
		listeners.add(listener);
	}
	
	

}
